<template>
  <div>
    <component-head title='联系人列表'></component-head>
    <div class="content">
      <van-address-list
        v-model="chosenAddressId"
        :list="contactlist"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
        @select="chhoseContact"   
      />
    </div>
  </div>
</template>

<script>
import componentHead from '@/views/car/components/component'
import { mapState, mapMutations } from 'vuex'
export default {
  components: {
    componentHead
  },
  computed: {
    ...mapState({
      contactlist: (state) => state.addcontact.contact
    })
  },
  data () {
    return {
      chosenAddressId: '1'
    }
  },
  methods: {
    // 点击切换地址时触发该函数
    chhoseContact (info) {
      console.log(info);
      this.choseContact(info)
    },
    onAdd () {
      // alert("添加")
      this.$router.push('/addcontent')
    },
    onEdit (contactlist,index) {
      // alert("修改")
      this.$router.push(`/contactedit/${index}`)
    },
    ...mapMutations('addcontact', ['choseContact'])
  }
}
</script>

<style lang="scss" scoped>
  .content{
    margin-top: 46px;
  }
</style>